//
//  HamatonBluetoothFunctionViewModel.swift
//  hamaton-app
//
//  Created by intyt on 2024/5/6.
//

import Foundation


// 将字符串按两个一组用冒号隔开 如：11223344转为11:22:33:44
extension String {
    func groupCharactersByTwoWithColon() -> String {
            var result = ""
            let characters = Array(self)
            
            for i in stride(from: 0, to: characters.count, by: 2) {
                let endIndex = min(i + 2, characters.count)
                let group = String(characters[i..<endIndex])
                result += group
                
                // 添加冒号，除非已经是最后一组
                if endIndex < characters.count {
                    result += ":"
                }
            }
            
            return result
        }
}
